/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQml 2.12

Item {
    property var pageContainer;
    signal indexchange(int index);
    z: 0
    function changeIndex(index) {
        if(index > pageContainer.currentIndex) {
            pageContainer.currentIndex += 1;
        }
        else if(index < pageContainer.currentIndex) {
            pageContainer.currentIndex -= 1;
        }
        else {
            return;
        }
    }
    PageIndicator {
        id: indicator;
        anchors.centerIn: parent
        delegate: Rectangle {
            width: indicator.currentIndex === index ?
                       15 * Style.tabletScaleFactor : 8 * Style.tabletScaleFactor
            height: 8 * Style.tabletScaleFactor;
            radius: indicator.width/2;
            color: "#FFFFFF";
            opacity: indicator.currentIndex === index ? 1 : 0.5;
            anchors.centerIn: parent.Center
        }

        count: pageContainer.count;
        currentIndex: pageContainer.currentIndex;
        interactive: true;
        onCurrentIndexChanged: {
            indexchange(indicator.currentIndex);
        }
    }

    PropertyAnimation {
        running: GroupController.groupPopuped
        target: indicator
        property: "scale"
        from: 1
        to: 0.9
        duration: 150
        easing.type: Easing.OutCubic
    }
    PropertyAnimation {
        running: !GroupController.groupPopuped
        target: indicator
        property: "scale"
        from: 0.9
        to: 1
        duration: 150
        easing.type: Easing.OutCubic
    }

    Component.onCompleted: {
        indexchange.connect(changeIndex);
    }
}
